package cn.wawi.controller.sys;

import java.util.LinkedHashMap;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import com.wawi.common.annotation.Permission;
import cn.wawi.controller.BaseController;
import cn.wawi.dao.sys.LogDao;
import cn.wawi.entity.sys.Log;
import com.wawi.utils.excel.ExcelFilter;
import com.wawi.utils.excel.ExcelUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping(value="/sys_log")
public class LogController extends BaseController<Log>{

	@Resource
	protected LogDao<Log> logDao;
	//String[] headers = new String[] {"id","用户","时间","描述","是否成功!","ip地址","系统","浏览器","请求参数","请求地址"};
	//String[] columns = new String[] {"id","optUser","inputTime","description","isSuccess","ip","os","browser","requestParam","operationCode"};
		
	@Permission("sys:log:exportExcel")
	@RequestMapping(value="/exportExcel")
	public void exportExcel(HttpServletResponse response){
		List<Log> list = logDao.findAll(paramaterMap);
		LinkedHashMap<String,String> fieldMap=new LinkedHashMap<String,String>();
		fieldMap.put("optUser", "用户名");
		fieldMap.put("realname", "姓名");
		fieldMap.put("ip", "ip地址");
		fieldMap.put("browser", "浏览器");
		fieldMap.put("os", "系统");
		fieldMap.put("isSuccess", "是否成功");
		fieldMap.put("operationCode", "请求地址");
		fieldMap.put("requestParam", "请求参数");
		fieldMap.put("inputTime", "时间");
		fieldMap.put("description", "描述");
		ExcelUtil.listToExcel(list, fieldMap, "日志列表", response,new ExcelFilter(){
			public Object doFilter(String name, Object value) {
				if("isSuccess".equals(name)){
					value="1".equals(value.toString())?"成功!":"失败!";
				}
				return value;
			}
			
		});
	}
	/**
	 *主页
	 */
	@RequestMapping(value="/main",method=RequestMethod.GET)
	public String main() {
		return "sys/Log/main";
	}
}
